@extends('admin.layout.index')

@section('content')

<div class="mws-panel grid_8">
	<div class="mws-panel-header">
    	<span><i class="icon-table"></i>{{$title}}</span>
    </div>
    <div class="mws-panel-body no-padding">
        <div id="DataTables_Table_1_wrapper" class="dataTables_wrapper" role="grid">
        <div id="DataTables_Table_1_length" class="dataTables_length">
        	<form method="get" action="/admin/admin">
        	<label>显示 
        		<select name="count" aria-controls="DataTables_Table_1">
	        		<option value="10" @if(!empty($request['count']) && $request['count'] == 10) selected @endif>10</option>
	        		<option value="20" @if(!empty($request['count']) && $request['count'] == 20) selected @endif>20</option>
	        		<option value="30" @if(!empty($request['count']) && $request['count'] == 30) selected @endif>30</option>
	        		<option value="50" @if(!empty($request['count']) && $request['count'] == 50) selected @endif>50</option>
	        	</select> 条</label>
	        </div>
	        <div class="dataTables_filter" id="DataTables_Table_1_filter">
	        	<label>关键字: <input type="text" name="search" value="{{$request['search'] or ''}}" aria-controls="DataTables_Table_1"><input type="submit" class="btn btn-success btn-xs" value="搜索"></label>
	        </div>
	        </form>
	        <table class="mws-datatable-fn mws-table dataTable" id="DataTables_Table_1" aria-describedby="DataTables_Table_1_info">
            <thead>
            	<tr>
            		<th>id</th>
                    <th>管理员名</th>
            		<th>状态</th>
            		<th colspan="2">操作</th>
            	</tr>
            </thead>
            
        <tbody role="alert" aria-live="polite" aria-relevant="all">
        		@foreach($data as $k=>$v)
        		<tr class="odd" style="text-align:center">
                    <td class="">{{$v->aid}}</td>
                    <td class="">{{$v->aname}}</td>
                    <td class="">{{$v->astatus ? "开启" : "关闭"}}</td>
                    <td style="width:200px">
                        @if($v->astatus)
                        <a href="/admin/admin/{{$v->aid}}"><button class="btn btn-info">关闭</button></a>
                        @else
                        <a href="/admin/admin/{{$v->aid}}"><button class="btn btn-success">开启</button></a>
                        @endif
                    </td>
                    <td class="" style="width:200px">
                    		<button class="btn btn-warning" onclick="delAdmin({{$v->aid}})">删除</button>
                    </td>
                </tr>
        		@endforeach
        </tbody></table>
		<div id="page_page" class="">
			{!! $data->appends($request)->render()!!}
		</div>

		</div>
    </div>
</div>
<script>
        function delAdmin(aid){

        layer.confirm('是否确认删除？', {
            btn: ['确认','取消'] //按钮
        }, function(){
            //            jQuery.post(url,data,success(data, textStatus, jqXHR),dataType)
            $.post('{{url("admin/admin/")}}/'+aid,{'_token':'{{csrf_token()}}','_method':'delete'},function(data){
                // 删除成功
                if(data.status == 0){
                    layer.msg(data.msg, {icon: 6});
                    location.href = location.href;
                }else{
                    layer.msg(data.msg, {icon: 5});
                    location.href = location.href;
                }
            });

        }, function(){

        });
    }
</script>
@endsection